package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目controller
 **/
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;


    @GetMapping
    @ApiOperation("分页查询护理项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理项目名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态: 0-禁用，1-启用", required = false, dataType = "int", paramType = "query"),
    })
    public ResponseResult<PageResponse<NursingProjectVo>> findByPage(@RequestParam(defaultValue = "1") int pageNum,
                                                                     @RequestParam(defaultValue = "10") int pageSize,
                                                                     @RequestParam(required = false) String name,
                                                                     @RequestParam(required = false) Integer status) {
        PageResponse<NursingProjectVo> byPage = nursingProjectService.findByPage(pageNum, pageSize, name, status);
        return success(byPage);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> findById(@PathVariable Long id) {
        NursingProjectVo byId = nursingProjectService.findById(id);
        return success(byId);
    }

    @PutMapping
    @ApiOperation("更新护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("更新护理项目状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "护理项目id", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "护理项目状态", required = true, dataType = "Integer", paramType = "path")
    })
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除护理项目信息")
    public ResponseResult deleteById(@PathVariable Long id) {
        nursingProjectService.deleteById(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目信息")
    public ResponseResult<List<NursingProjectVo>> findAll() {
        List<NursingProjectVo> list = nursingProjectService.findAll();
        return success(list);
    }




}
